import { extend } from 'umi-request';

const request = extend({
    prefix: 'http://101.200.238.241:8080',
    // prefix: '/api',//baseURL
    timeout: 5000,//超时时间
    headers: {
        'Content-Type': 'application/json',
    },
});
request.interceptors.request.use((url, options) => {
    let token = sessionStorage.getItem('token') || 'abc';
    console.log(options);
    
    if (token) {
        options.headers = {
            ...options.headers,
            token: token
        }
    }
    return {
        url: url,
        options: options,
    };
});

request.interceptors.response.use(async (response, options) => {
    const res:any=response
    return res
    // switch(res.code){
    //     case 0:
    //         return res;
    //     case 200:
    //         return res;
    //     case 500:
    //         return res;
    //     case 401:
    //         console.log('token失效')
    //         window.location.href='http://localhost:8000'
    // }
});

export default request;